# 1) 内地电影票房前 20 的电影（列表 a）a = ["战狼 2","速度与激情8","功夫瑜伽"," 西游伏妖篇","变形金刚 5：最后的骑士","摔跤吧！爸爸","加勒比海盗5：死无对证","金刚：骷髅岛",
# "极限特工：终极回归","生化危机6：终章","乘风破浪"," 神偷奶爸 3","智取威虎山","大闹天竺","金刚狼 3：殊死一战","蜘蛛侠：英雄归来","悟空传","银河护卫队 2","情圣","新木乃伊",]
# 2) 电影票房数据（列表 b）b= [56.01,26.94,17.53,16.49,15.45,12.96,11.8,11.61,11.28, 11.12,10.49,10.3,8.75,7.55,7.32,6.99,6.88,6.86,6.58,6.23]

import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
x = ["战狼 2", "速度与激情8", "功夫瑜伽", " 西游伏妖篇", "变形金刚 5：最后的骑士", "摔跤吧！爸爸", "加勒比海盗5：死无对证", "金刚：骷髅岛", "极限特工：终极回归", "生化危机6：终章",
     "乘风破浪", " 神偷奶爸 3", "智取威虎山", "大闹天竺", "金刚狼 3：殊死一战", "蜘蛛侠：英雄归来", "悟空传", "银河护卫队 2", "情圣", "新木乃伊", ]
y = [56.01, 26.94, 17.53, 16.49, 15.45, 12.96, 11.8, 11.61, 11.28, 11.12, 10.49, 10.3, 8.75, 7.55, 7.32, 6.99, 6.88,
     6.86, 6.58, 6.23]
# 水平条形图的宽细得用height设置粗细
plt.barh(x, y, height =0.3, color='orange')
plt.title('2020年票房前20电影')
plt.ylabel('电影名称')
plt.xlabel('票房')
# 自动调整布局
plt.tight_layout()
plt.show()
# 保存图形
# plt.savefig('G:\\下载\\figure.png', bbox_inches='tight', dpi=300)  # 默认保存为PNG格式
# plt.close()  # 关闭图形，释放内存
